﻿/*
 *  RetroGlider v1.0
    Copyright (C) 2013 Alexander Blohmé

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenHack;
using System.Diagnostics;

namespace RetroGlider
{
    public class WoWEngine
    {

        public WalkEngine WalkSystem = new WalkEngine();

        
        private Boolean init()
        {
            GameReader WoW = Globals.WoWGame;
            WoW.init();
            Boolean retVal = WoW.LoadAddresses();

            return retVal;
        }

        public string TimeToLevel()
        {
            return null;
        }

        public string ExpHour()
        {
            return null;
        }

        

        public int TargetHealth()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            return (int)TargetPlayer.CurrentHealth;
        }

        public int TargetMP()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            return (int)TargetPlayer.CurrentEnergy;
        }

        public int TargetLevel()
        {
            
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            
            return (int)TargetPlayer.Level;
            
        }

        public bool HaveTarget()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            try
            {
                int cool = (int)TargetPlayer.Level;
                return true;
            }
            catch 
            {
                 return false;
            }
            return false;
        }


        public float TargetXPosition()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            return TargetPlayer.XPos;
        }

        public float TargetYPosition()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();
            return TargetPlayer.YPos;
        }

        public float TargetZPosition()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();
            return TargetPlayer.ZPos;
        }

        public float TargetFacingPosition()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();
            return TargetPlayer.Facing;
        }

        public int PlayerMaxHealth()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();
            return (int)LocalPlayer.MaxHealth;
        }

        public int PlayerMaxMana()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();
            return (int)LocalPlayer.MaxEnergy;
        }


        public int PlayerHealth()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();
            return (int)LocalPlayer.CurrentHealth;
        }
        public int PlayerLevel()
        {
            GameReader WoW = Globals.WoWGame;

            WowObject LocalPlayer = WoW.getLocalPlayer();

            return (int)LocalPlayer.Level;
        }

        public float PlayerXPosition()
        {
            GameReader WoW = Globals.WoWGame;

            WowObject LocalPlayer = WoW.getLocalPlayer();

            return LocalPlayer.XPos;
        }

        public float PlayerYPosition()
        {
            GameReader WoW = Globals.WoWGame;

            WowObject LocalPlayer = WoW.getLocalPlayer();

            return LocalPlayer.YPos;
        }

        public float PlayerFacingPosition()
        {
            GameReader WoW = Globals.WoWGame;

            WowObject LocalPlayer = WoW.getLocalPlayer();

            return LocalPlayer.Facing;
        }

        public int PlayerMana()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();

            return (int)LocalPlayer.CurrentEnergy;
        }

        public int TargetMaxMana()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();

            return (int)LocalPlayer.MaxEnergy;
        }

        public int TargetMaxHealth()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();

            return (int)LocalPlayer.MaxHealth;
        }

        public string TargetName()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();

            return TargetPlayer.Name;
        }

        public string PlayerName()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();

            return LocalPlayer.Name;
        }

        public float PlayerRotation()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject LocalPlayer = WoW.getLocalPlayer();
            return LocalPlayer.Rotation;
        }

        public float TargetRotation()
        {
            GameReader WoW = Globals.WoWGame;
            WowObject TargetPlayer = WoW.getLocalTarget();
            return TargetPlayer.Rotation;
        }

       /* public string testInfo()
        {
            GameReader WoW = Globals.WoWGame;
            //WowObject Info = WoW.getLocalTarget;
            
        }*/


        public bool InitWoW()
        {
            int pid = 0;
            foreach (Process process in Process.GetProcessesByName("Wow"))
            {
                pid = process.Id;
              
            }

            Globals.Process = Process.GetProcessById(pid);
            if (!Globals.Magic.OpenProcessAndThread(pid))
            {
                return false;
            }

            Offsets.Initialize();
            init();
            return true;
 

        }

        public void StartBot()
        {
            

        }




    }
}
